class Solution 
{
public:
    int eraseOverlapIntervals(vector<vector<int>>& intervals)   // 贪心法解无重叠区间问题
    {
        if (intervals.empty())
        {
            return 0;
        }

        sort(intervals.begin(), intervals.end(), [&](vector<int>& elem1, vector<int>& elem2)
        {
            return elem1.back() < elem2.back();           // 按区间右端点由小到大进行排序
        });

        int right = intervals.front().back();
        int ret = 1;
        for (size_t i = 1; i < intervals.size(); i++)
        {
            if(intervals[i].front() >= right)
            {
                ret ++;
                right = intervals[i].back();
            }

        }
        return intervals.size() - ret;


    }
};